import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class Reveres {
  Reveres({
    this.status,
    this.result,
  });

  factory Reveres.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Reveres(
    status: asT<int>(jsonRes['status']),
    result: Result.fromJson(asT<Map<String, dynamic>>(jsonRes['result'])),
  );

  int status;
  Result result;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'status': status,
    'result': result,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Result {
  Result({
    this.location,
    this.formatted_address,
    this.business,
    this.addressComponent,
    this.pois,
    this.roads,
    this.poiRegions,
    this.sematic_description,
    this.cityCode,
  });

  factory Result.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Pois> pois = jsonRes['pois'] is List ? <Pois>[] : null;
    if (pois != null) {
      for (final dynamic item in jsonRes['pois']) {
        if (item != null) {
          pois.add(Pois.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }

    final List<Object> roads = jsonRes['roads'] is List ? <Object>[] : null;
    if (roads != null) {
      for (final dynamic item in jsonRes['roads']) {
        if (item != null) {
          roads.add(asT<Object>(item));
        }
      }
    }

    final List<PoiRegions> poiRegions =
    jsonRes['poiRegions'] is List ? <PoiRegions>[] : null;
    if (poiRegions != null) {
      for (final dynamic item in jsonRes['poiRegions']) {
        if (item != null) {
          poiRegions.add(PoiRegions.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return Result(
      location:
      Location.fromJson(asT<Map<String, dynamic>>(jsonRes['location'])),
      formatted_address: asT<String>(jsonRes['formatted_address']),
      business: asT<String>(jsonRes['business']),
      addressComponent: AddressComponent.fromJson(
          asT<Map<String, dynamic>>(jsonRes['addressComponent'])),
      pois: pois,
      roads: roads,
      poiRegions: poiRegions,
      sematic_description: asT<String>(jsonRes['sematic_description']),
      cityCode: asT<int>(jsonRes['cityCode']),
    );
  }

  Location location;
  String formatted_address;
  String business;
  AddressComponent addressComponent;
  List<Pois> pois;
  List<Object> roads;
  List<PoiRegions> poiRegions;
  String sematic_description;
  int cityCode;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'location': location,
    'formatted_address': formatted_address,
    'business': business,
    'addressComponent': addressComponent,
    'pois': pois,
    'roads': roads,
    'poiRegions': poiRegions,
    'sematic_description': sematic_description,
    'cityCode': cityCode,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Location {
  Location({
    this.lng,
    this.lat,
  });

  factory Location.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Location(
    lng: asT<double>(jsonRes['lng']),
    lat: asT<double>(jsonRes['lat']),
  );

  double lng;
  double lat;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'lng': lng,
    'lat': lat,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class AddressComponent {
  AddressComponent({
    this.country,
    this.country_code,
    this.country_code_iso,
    this.country_code_iso2,
    this.province,
    this.city,
    this.city_level,
    this.district,
    this.town,
    this.town_code,
    this.adcode,
    this.street,
    this.street_number,
    this.direction,
    this.distance,
  });

  factory AddressComponent.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : AddressComponent(
        country: asT<String>(jsonRes['country']),
        country_code: asT<int>(jsonRes['country_code']),
        country_code_iso: asT<String>(jsonRes['country_code_iso']),
        country_code_iso2: asT<String>(jsonRes['country_code_iso2']),
        province: asT<String>(jsonRes['province']),
        city: asT<String>(jsonRes['city']),
        city_level: asT<int>(jsonRes['city_level']),
        district: asT<String>(jsonRes['district']),
        town: asT<String>(jsonRes['town']),
        town_code: asT<String>(jsonRes['town_code']),
        adcode: asT<String>(jsonRes['adcode']),
        street: asT<String>(jsonRes['street']),
        street_number: asT<String>(jsonRes['street_number']),
        direction: asT<String>(jsonRes['direction']),
        distance: asT<String>(jsonRes['distance']),
      );

  String country;
  int country_code;
  String country_code_iso;
  String country_code_iso2;
  String province;
  String city;
  int city_level;
  String district;
  String town;
  String town_code;
  String adcode;
  String street;
  String street_number;
  String direction;
  String distance;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'country': country,
    'country_code': country_code,
    'country_code_iso': country_code_iso,
    'country_code_iso2': country_code_iso2,
    'province': province,
    'city': city,
    'city_level': city_level,
    'district': district,
    'town': town,
    'town_code': town_code,
    'adcode': adcode,
    'street': street,
    'street_number': street_number,
    'direction': direction,
    'distance': distance,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Pois {
  Pois({
    this.addr,
    this.cp,
    this.direction,
    this.distance,
    this.name,
    this.poiType,
    this.point,
    this.tag,
    this.tel,
    this.uid,
    this.zip,
    this.parent_poi,
  });

  factory Pois.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Pois(
    addr: asT<String>(jsonRes['addr']),
    cp: asT<String>(jsonRes['cp']),
    direction: asT<String>(jsonRes['direction']),
    distance: asT<String>(jsonRes['distance']),
    name: asT<String>(jsonRes['name']),
    poiType: asT<String>(jsonRes['poiType']),
    point: Point.fromJson(asT<Map<String, dynamic>>(jsonRes['point'])),
    tag: asT<String>(jsonRes['tag']),
    tel: asT<String>(jsonRes['tel']),
    uid: asT<String>(jsonRes['uid']),
    zip: asT<String>(jsonRes['zip']),
    parent_poi: Parent_poi.fromJson(
        asT<Map<String, dynamic>>(jsonRes['parent_poi'])),
  );

  String addr;
  String cp;
  String direction;
  String distance;
  String name;
  String poiType;
  Point point;
  String tag;
  String tel;
  String uid;
  String zip;
  Parent_poi parent_poi;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'addr': addr,
    'cp': cp,
    'direction': direction,
    'distance': distance,
    'name': name,
    'poiType': poiType,
    'point': point,
    'tag': tag,
    'tel': tel,
    'uid': uid,
    'zip': zip,
    'parent_poi': parent_poi,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Point {
  Point({
    this.x,
    this.y,
  });

  factory Point.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Point(
    x: asT<double>(jsonRes['x']),
    y: asT<double>(jsonRes['y']),
  );

  double x;
  double y;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'x': x,
    'y': y,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Parent_poi {
  Parent_poi({
    this.name,
    this.tag,
    this.addr,
    this.point,
    this.direction,
    this.distance,
    this.uid,
  });

  factory Parent_poi.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Parent_poi(
    name: asT<String>(jsonRes['name']),
    tag: asT<String>(jsonRes['tag']),
    addr: asT<String>(jsonRes['addr']),
    point: Point.fromJson(asT<Map<String, dynamic>>(jsonRes['point'])),
    direction: asT<String>(jsonRes['direction']),
    distance: asT<String>(jsonRes['distance']),
    uid: asT<String>(jsonRes['uid']),
  );

  String name;
  String tag;
  String addr;
  Point point;
  String direction;
  String distance;
  String uid;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'name': name,
    'tag': tag,
    'addr': addr,
    'point': point,
    'direction': direction,
    'distance': distance,
    'uid': uid,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class PoiRegions {
  PoiRegions({
    this.direction_desc,
    this.name,
    this.tag,
    this.uid,
    this.distance,
  });

  factory PoiRegions.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : PoiRegions(
    direction_desc: asT<String>(jsonRes['direction_desc']),
    name: asT<String>(jsonRes['name']),
    tag: asT<String>(jsonRes['tag']),
    uid: asT<String>(jsonRes['uid']),
    distance: asT<String>(jsonRes['distance']),
  );

  String direction_desc;
  String name;
  String tag;
  String uid;
  String distance;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'direction_desc': direction_desc,
    'name': name,
    'tag': tag,
    'uid': uid,
    'distance': distance,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}
